@model CleverCMS.Cms.Data.Entities.CmsSetting

@section TitleContent
{
    @((Model != null && Model.Id != 0) ? "Edit Widget" : "New Widget")
}

@section HeadContent
{
    <script type="text/javascript">
        function successSave(e) {
            if (e.success) {
                var pageId = e.id;
                $('#Id').val(pageId);
                $("#failureResult").hide();
                $("#successResult").show().fadeOut(5000);
            } else {
                $("#errortext").html(e.error);
                $("#failureResult").fadeIn(1000);
            }
        }
        function failureSave() {
            $("#failureResult").show().fadeIn(700);
        }

        $(document).ready(function () {
            $("button[type=submit]").on("click", function () {
                $("html, body").animate({ scrollTop: 0 }, "slow");
            });
        });
    </script>
}

<div class="widget green">
    <div class="widget-title">
        <h4><i class="icon-reorder"></i> Widget</h4>
        <span class="tools">
            <a class="icon-chevron-down" href="javascript:;"></a>
            <a class="icon-remove" href="javascript:;"></a>
        </span>
    </div>
    <div class="widget-body">
            
        <div id="failureResult" class="alert alert-block alert-error" style="display: none">
            <h4 class="alert-heading">Error!</h4>
            <p id="errortext">
            </p>
        </div>

        <div class="alert alert-block alert-success" style="display: none" id="successResult">
            <h4 class="alert-heading">Success!</h4>
            <p>
                Items was successfully saved.
            </p>
        </div>

        @using (Ajax.BeginForm("Edit", "Settings", new AjaxOptions { HttpMethod = "POST", OnFailure = "failureSave", OnSuccess = "successSave" }, new { id = "editSiteSettingForm", @class = "search_form general_form" }))
        {
            @Html.HiddenFor(x => x.Id)
            @Html.HiddenFor(x => x.CreatedAt)
            <div class="module_content">
                <fieldset>
                    <label>Key:</label>
                    @Html.ValidationMessageFor(x => x.Key)
                    @Html.TextBoxFor(x => x.Key, new { @class = "text large", @style = "width: 30%" })
                </fieldset>
                <fieldset>
                    <label>Value:</label>
                    @Html.ValidationMessageFor(x => x.Value)
                    @Html.TextAreaFor(x => x.Value, 15, 10, new { @class = "text", @style = "width: 30%" })
                </fieldset>
            </div>
            <button type="submit" class="btn btn-success" name="save_setting"><i class="icon-ok icon-white"></i> Save</button>
            <button class="btn btn-inverse" onclick="resetFields(this); return false;"><i class="icon-refresh icon-white"></i> Reset</button>
            <button class="btn btn-inverse" onclick="history.back()"><i class="icon-ban-circle icon-white"></i> Back</button> 
        }   
    </div>
</div>